const QQMapWX = require('./utils/qqmap-wx-jssdk.min.js') //导入SDK核心类
const bamp = require('./utils/bmap-wx.min.js')
// 实例化API类
let qqmapsdk = new QQMapWX({
  key: 'D22BZ-GYCKX-OCR4T-7I7PZ-VHYLS-L3BCL'
});
App({
  onLaunch: function () {
    let appid = 'wx6ed2c12c753f749e'
    wx.setStorageSync('appid', appid)
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    wx.getSystemInfo({
      success: res => {
        let num = 0;
        if (res.platform == "devtools") {
          num = 4
        } else if (res.platform == "android") {
          num = 2;
        }
        let statusBarHeight = res.statusBarHeight,
          navTop = menuButtonObject.top, //胶囊按钮与顶部的距离
          navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2; //导航高度
        this.globalData.navHeight = navHeight;
        this.globalData.navTop = navTop;
        this.globalData.windowHeight = res.windowHeight;
        this.globalData.enuButtonHeight = menuButtonObject.height + num;
      },
      fail(err) {
        console.log(err);
      }
    })

    // 获取用户的地理位置信息
    wx.getLocation({
      type: 'wgs84',
      success(res) {
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: res => {
            wx.setStorageSync('site', res.result.address_component)
            let BMap = new bamp.BMapWX({
              ak: 'DALhOvbBew0y0XO9gp5EGhvWq7pfdmLO'
            })
        
            
            let fail = function (data) {
              // console.log(data,']');
            }
    

            let success = function (data) {
              
              data.currentWeather[0].currentCity = res.result.address_component.district
              wx.setStorageSync('weather', data)
              // console.log(data)
            }
            BMap.weather({
              fail: fail,
              success: success
            })
          },
          fail: res => {
            console.log(res)
          }
        })
      }
    })
  },
  globalData: {
    navHeight: null,
    navTop: null,
    windowHeight: null,
    enuButtonHeight: null
  }
})






